#ifndef _LIS2DH12_H_
#define _LIS2DH12_H_
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include "stm32l0xx_hal.h"

/**
 * @brief  IMU_6AXES status enumerator definition
 */

#define LIS2DH12_SAMPLE_NUMBER    0x14
 
#define LIS2DH12_ADDRESS  0x32 

#define I_AM_LIS2DH12          0x33
 
#define LIS2DH12_REG_WHO_AM_I         0x0F

/*register*/
#define LIS2DH12_REG_CTRL_REG1        0x20
#define LIS2DH12_REG_CTRL_REG2        0x21
#define LIS2DH12_REG_CTRL_REG3        0x22
#define LIS2DH12_REG_CTRL_REG4        0x23
#define LIS2DH12_REG_CTRL_REG5        0x24
#define LIS2DH12_REG_CTRL_REG6        0x25
#define LIS2DH12_REG_REFERENCE_REG     0x26

#define LIS2DH12_REG_OUT_FIFO          0xA8

#define LIS2DH12_REG_OUT_X_L          0x28
#define LIS2DH12_REG_OUT_X_H          0x29
#define LIS2DH12_REG_OUT_Y_L          0x2A
#define LIS2DH12_REG_OUT_Y_H          0x2B
#define LIS2DH12_REG_OUT_Z_L          0x2C
#define LIS2DH12_REG_OUT_Z_H          0x2D

#define LIS2DH12_REG_FIFO_CTRL        0x2E
#define LIS2DH12_REG_FIFO_SRC_REG     0x2F
#define LIS2DH12_REG_INT1_SRC_REG     0x31


/*fifo mode*/

#define  LIS2DH12_FIFO_MODE_BYPASS          0x00
#define  LIS2DH12_FIFO_MODE_FIFO            0x40  
#define  LIS2DH12_FIFO_MODE_STREAM          0x80
#define  LIS2DH12_FIFO_MODE_STREAM_TO_FIFO  0xC0
#define LIS2DH12_FIFO_MODE_MASK             0xC0
/*fifo fth value*/
#define LIS2DH12_FIFO_FTH_VALUE_MASK    0x1F
/*fifo TR int*/
#define LIS2DH12_TR_INT1                0x00
#define LIS2DH12_TR_INT2                0x20
#define LIS2DH12_FIFO_TR_INT_MASK       0x20
    

/*fifo watermark int1 enable*/
#define LIS2DH12_WTM_INT1_DISABLE       0x00
#define LIS2DH12_WTM_INT1_ENABLE        0x04
#define LIS2DH12_WTM_INT1_ENABLE_MASK   0x04

#define LIS2DH12_OVERRUN_INT1_ENABLE        0x02
#define LIS2DH12_OVERRUN_INT1_ENABLE_MASK   0x02

/*ODR set*/

#define  LIS2DH12_POWER_DOWN            0x00
#define  LIS2DH12_ODR_1HZ               0x10
#define  LIS2DH12_ODR_10HZ              0x20
#define  LIS2DH12_ODR_25HZ              0x30
#define  LIS2DH12_ODR_50HZ              0x40
#define  LIS2DH12_ODR_100HZ             0x50
#define  LIS2DH12_ODR_200HZ             0x60
#define  LIS2DH12_ODR_400HZ             0x70
#define  LIS2DH12_ODR_LP_1620HZ         0x80
#define  LIS2DH12_ODR_LP_5376HZ         0x90
#define LIS2DH12_ODR_MASK               0xF0

/*BDU set*/
#define LIS2DH12_BDU_SET             0x80
#define LIS2DH12_BDU_SET_MASK        0x80

/*Full-scall set*/
#define LIS2DH12_FS_2G              0x00
#define LIS2DH12_FS_4G              0x10
#define LIS2DH12_FS_8G              0x20
#define LIS2DH12_FS_16G             0x30
#define LIS2DH12_FS_SET_MASK        0x30

/*self test */
#define LIS2DH12_SELFTEST_DISABLE     0x00
#define LIS2DH12_SELFTEST_MODE_0      0x02
#define LIS2DH12_SELFTEST_MODE_1      0x04
#define LIS2DH12_SELFTEST_MODE_MASK   0x06

/*power mode*/
#define LIS2DH12_NORMAL_MODE               0x00
#define LIS2DH12_HIGH_RESOLUTION_MODE      0x01
#define LIS2DH12_LOW_POWER_MODE            0x02
#define LIS2DH12_POWER_MODE_MASK           0x08

/*fifo enable*/
#define LIS2DH12_FIFO_DISABLE        0x00
#define LIS2DH12_FIFO_ENABLE         0x40
#define LIS2DH12_FIFO_ENABLE_MASK    0x40

/*latch*/
#define LIS2DH12_LATCH_INT1_DISABLE        0x00
#define LIS2DH12_LATCH_INT1_ENABLE         0x08
#define LIS2DH12_LATCH_INT1_ENABLE_MASK    0x08

/*x,y,z axis enable*/
#define  LIS2DH12_AXIS_DISABLE       0x00
#define  LIS2DH12_AXIS_X_ENABLE      0x01
#define  LIS2DH12_AXIS_Y_ENABLE      0x02
#define  LIS2DH12_AXIS_Z_ENABLE      0x04
#define  LIS2DH12_AXIS_ENABLE_MASK   0x07

/*sensitivity*/
#define  LIS2DH12_2G_SENSITIVITY      0x02
#define  LIS2DH12_4G_SENSITIVITY      0x04
#define  LIS2DH12_8G_SENSITIVITY      0x08
#define  LIS2DH12_16G_SENSITIVITY     0x10

#define  LIS2DH12_HIGH_RESOLUTION_MODE_SENSITIVITY_MULTIPLE     0x01
#define  LIS2DH12_NORMAL_MODE_SENSITIVITY_MULTIPLE              0x04
#define  LIS2DH12_LOW_POWER_MODE_SENSITIVITY_MULTIPLE           0x10



typedef enum
{
  LIS2DH12_OK = 0,
  LIS2DH12_ERROR = 1,
  LIS2DH12_TIMEOUT = 2,
  LIS2DH12_NOT_IMPLEMENTED = 3
} LIS2DH12_StatusTypeDef;

typedef struct
{
  float X_OutputDataRate;
  float X_FullScale;
  uint8_t X_X_Axis;
  uint8_t X_Y_Axis;
  uint8_t X_Z_Axis;
} LIS2DH12_InitTypeDef;

typedef struct _LIS2DH12_Axis_type_t{
 int16_t axis_x;
 int16_t axis_y;
 int16_t axis_z;
}lis2dh12_axis_type_t;

/*Public function**********************************************************************************/
LIS2DH12_StatusTypeDef LIS2DH12_Read_Id(uint8_t* data);
LIS2DH12_StatusTypeDef LIS2DH12_Read_Fifo_Byte_Number(uint8_t* data);
LIS2DH12_StatusTypeDef LIS2DH12_Read_INT1_SRC(uint8_t* data);
LIS2DH12_StatusTypeDef LIS2DH12_Init(void);
LIS2DH12_StatusTypeDef LIS2DH12_FIFO_Mode_Set(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_TR_Select(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_FIFO_FTH_Value_Set(uint16_t data);
LIS2DH12_StatusTypeDef LIS2DH12_FIFO_OVERRUN_INT1_Enable(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_FIFO_WTM_INT1_Enable(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_Data_Rate_Set(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_BDU_Set(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_FS_Set(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_Power_Mode_Set(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_FIFO_Enable(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_FIFO_Buffer_Reset(void);
LIS2DH12_StatusTypeDef LIS2DH12_Axis_Enable(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_Selftest_Mode_Set(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_Get_Sensitivity(float* sensitivity);
LIS2DH12_StatusTypeDef LIS2DH12_X_Y_Z_Get_Axes_Raw(void);
LIS2DH12_StatusTypeDef LIS2DH12_X_Y_Z_Get_Axes_Data(float *pData);
LIS2DH12_StatusTypeDef LIS2DH12_Reference_Set(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_Latch_Int_On_Int1_Src(uint8_t data);
LIS2DH12_StatusTypeDef LIS2DH12_INT_IO_ITConfig(void);

LIS2DH12_StatusTypeDef LIS2DH12_Reg_Read(uint8_t reg, uint8_t* data);



#endif //_LIS2DH12_H_
